import { app, BrowserWindow, Menu, Tray } from 'electron'
import path from 'path'

// 创建托盘图标
export function createTray(windowInstance: BrowserWindow) {
  const iconPath = path.join(__dirname, '../../resources/cc.jpg')
  const tray = new Tray(iconPath)

  // 创建托盘菜单
  const contextMenu = Menu.buildFromTemplate([
    {
      label: 'Show',
      click: () => {
        windowInstance.show()
        windowInstance.focus()
      }
    },
    {
      label: 'Quit',
      click: () => {
        app.quit()
      }
    }
  ])

  tray.setContextMenu(contextMenu)

  // 点击托盘图标时显示窗口
  tray.on('click', () => {
    windowInstance.show()
    windowInstance.focus()
  })
}
